package com.shanghaionstar.nav.presenter;

import android.content.res.Resources;
import android.support.v4.app.FragmentManager;

import com.onstar.cn.framework.mvp.base.IMVPScheduler;
import com.onstar.cn.framework.mvp.base.IMVPView;
import com.onstar.cn.framework.mvp.base.core.BasePresenter;
import com.onstar.cn.map.common.PoiItemInfo;
import com.onstar.cn.map.common.PoiType;
import com.shanghaionstar.enumtype.FunctionNameFindId;
import com.shanghaionstar.nav.NavSearchMoreFragment;
import com.shanghaionstar.nav.NavSearchTypeFragment;
import com.shanghaionstar.nav.iview.INavSearchMoreView;
import com.shanghaionstar.nav.service.AbstractMapActivity;
import com.shanghaionstar.utils.BusinessUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 6335yz on 2016/7/7.
 */
public class NavSearchMorePresenter extends BasePresenter {

    private AbstractMapActivity mapActivity;
    private Resources res;
    private INavSearchMoreView navSearchMoreView;
    private List<PoiItemInfo> searchPoiList;
    private FragmentManager fragmentManager;

    @Override
    public void setView(IMVPView view) {
        super.setView(view);
        navSearchMoreView = (INavSearchMoreView) view;
    }

    public NavSearchMorePresenter(IMVPScheduler mvpScheduler, AbstractMapActivity mapActivity) {
        super(mvpScheduler);
        this.mapActivity = mapActivity;
        res = this.mapActivity.getResources();
        fragmentManager = mapActivity.getSupportFragmentManager();
    }

    /**
     * 加载搜索选项栏
     */
    public void loadSearchItem(int[] gridViewImages, String[] gridViewTextInfos) {
        List<Map<String, Object>> items = new ArrayList<Map<String, Object>>();
        for (int i = 0; i < gridViewImages.length; i++) {
            Map<String, Object> item = new HashMap<String, Object>();
            item.put("grid_image", gridViewImages[i]);
            item.put("text_item_info", gridViewTextInfos[i]);
            items.add(item);
        }
        if (navSearchMoreView != null) {
            navSearchMoreView.showSearchItem(items);
        }
    }

    public void onGridViewItemClick(int position, String[] gridViewTextInfos) {
        NavSearchTypeFragment navSearchTypeFragment = null;
        switch (position) {
            case 0:// 交通设施
                BusinessUtil.sendReportByClickType(mapActivity, FunctionNameFindId.Categorysearchmore_transportation.getStringValue());
                navSearchTypeFragment = NavSearchTypeFragment.newInstance(gridViewTextInfos[position], PoiType.Traffic.getStringValue());
                break;
            case 1://  餐饮住宿
                BusinessUtil.sendReportByClickType(mapActivity, FunctionNameFindId.Categorysearchmore_foodandrodging.getStringValue());
                navSearchTypeFragment = NavSearchTypeFragment.newInstance(gridViewTextInfos[position], PoiType.RoomAndBoard.getStringValue());
                break;
            case 2:// 购物商场
                BusinessUtil.sendReportByClickType(mapActivity, FunctionNameFindId.Categorysearchmore_shopping.getStringValue());
                navSearchTypeFragment = NavSearchTypeFragment.newInstance(gridViewTextInfos[position], PoiType.Shopping.getStringValue());
                break;
            case 3:// 生活服务
                BusinessUtil.sendReportByClickType(mapActivity, FunctionNameFindId.Categorysearchmore_livingservice.getStringValue());
                navSearchTypeFragment = NavSearchTypeFragment.newInstance(gridViewTextInfos[position], PoiType.Dailylife.getStringValue());
                break;
            case 4://车辆
                BusinessUtil.sendReportByClickType(mapActivity, FunctionNameFindId.Categorysearchmore_vehicle.getStringValue());
                navSearchTypeFragment = NavSearchTypeFragment.newInstance(gridViewTextInfos[position], PoiType.Vehicle.getStringValue());
                break;
            case 5://体育休闲
                BusinessUtil.sendReportByClickType(mapActivity, FunctionNameFindId.Categorysearchmore_sportsandrecreation.getStringValue());
                navSearchTypeFragment = NavSearchTypeFragment.newInstance(gridViewTextInfos[position], PoiType.SportsRecreation.getStringValue());
                break;
            case 6:// 风景名胜
                BusinessUtil.sendReportByClickType(mapActivity, FunctionNameFindId.Categorysearchmore_spot.getStringValue());
                navSearchTypeFragment = NavSearchTypeFragment.newInstance(gridViewTextInfos[position], PoiType.TouristAttraction.getStringValue());
                break;
            case 7:// 政府机构
                BusinessUtil.sendReportByClickType(mapActivity, FunctionNameFindId.Categorysearchmore_government.getStringValue());
                navSearchTypeFragment = NavSearchTypeFragment.newInstance(gridViewTextInfos[position], PoiType.Organizations.getStringValue());
                break;
            case 8:// 商业服务
                BusinessUtil.sendReportByClickType(mapActivity, FunctionNameFindId.Categorysearchmore_business.getStringValue());
                navSearchTypeFragment = NavSearchTypeFragment.newInstance(gridViewTextInfos[position], PoiType.Business.getStringValue());
                break;
            case 9:// 其他
                BusinessUtil.sendReportByClickType(mapActivity, FunctionNameFindId.Categorysearchmore_other.getStringValue());
                navSearchTypeFragment = NavSearchTypeFragment.newInstance(gridViewTextInfos[position], PoiType.Other.getStringValue());
                break;
        }
        if(navSearchTypeFragment!=null) {
            mapActivity.addFragment(fragmentManager, navSearchTypeFragment, true);
            mapActivity.showFragment(fragmentManager, NavSearchTypeFragment.class, NavSearchMoreFragment.class);
        }
    }
}
